package com.example.bookshop.service.user;

import com.example.bookshop.entity.BaseGoods;
import com.example.bookshop.entity.Cart;
import com.example.bookshop.repository.CartRepository;
import com.example.bookshop.repository.GoodsRepository;
import com.example.bookshop.result.Result;
import com.example.bookshop.util.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Service
public class CartServiceImpl implements CartService{
    @Autowired
    CartRepository cartRepository;
    @Autowired
    GoodsRepository goodsRepository;
    @Override
    public List<BaseGoods> getCart(HttpSession session) {
        MyUtil myUtil=new MyUtil();
        List<Integer>list=cartRepository.findCartByUserId(myUtil.getUserId(session));
        return goodsRepository.findListGoods(list);
    }

    @Override
    public Result addCart(Cart cart) {
        int i=cartRepository.addCart(cart);
        if(i==1) {
            return new Result(200);
        }
        else return new Result(400);
    }
}
